<?php
namespace app\models;
use common\component\tool\Tool;
use app\models\Basic;

use Yii;

class DynamicDataInfo extends Basic
{
    
    public static function tableName()
    {
        return '{{%dynamic_data_info}}';
    }

    public function rules()
    {
        return [
            ['app_id', 'required', 'message' => 'app_id不能为空', 'on' => 'add'],
            ['app_id', 'integer', 'message' => 'app_id必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'app_id最小存储0', 
                        'max'=>18446744073709551615, 'tooBig' => 'app_id最大存储18446744073709551615'],
            ['dynamic_id', 'required', 'message' => 'dynamic_id不能为空'],
            ['dynamic_id', 'integer', 'message' => 'dynamic_id必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'dynamic_id最小存储0', 
                        'max'=>18446744073709551615, 'tooBig' => 'dynamic_id最大存储18446744073709551615'],
            ['flagnum', 'required', 'message' => 'flagnum不能为空'],
            ['flagnum', 'integer', 'message' => 'flagnum必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'flagnum最小存储0', 
                        'max'=>255, 'tooBig' => 'flagnum最大存储255'],         
            ['member_id', 'required', 'message' => 'member_id不能为空'],
            ['member_id', 'integer', 'message' => 'member_id必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'member_id最小存储0', 
                        'max'=>18446744073709551615, 'tooBig' => 'member_id最大存储18446744073709551615'],
            ['ip', 'string', 'message' => 'ip必须是字符串', 
                            'max' => 64, 'tooLong' => 'ip最长64位'],  
            ['sessionid', 'string', 'message' => 'sessionid必须是字符串', 
                            'max' => 32, 'tooLong' => 'sessionid最长32位'],
            ['client', 'string', 'message' => 'client必须是字符串', 
                            'max' => 512, 'tooLong' => 'client最长512位'],               
            ['praise_num', 'integer', 'message' => 'praise_num必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'praise_num最小存储0', 
                        'max'=>18446744073709551615, 'tooBig' => 'praise_num最大存储18446744073709551615'],
            ['reply_num', 'integer', 'message' => 'reply_num必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'reply_num最小存储0', 
                        'max'=>18446744073709551615, 'tooBig' => 'dynamic_id最大存储18446744073709551615'],
            ['state', 'integer', 'message' => 'state必须为数字，或数字字符串'],
            ['state', 'in', 'range' => array(1, 2, 3), 'message' => 'state值必须在1~3中选择'], 
            ['add_time', 'default', 'value' => '1000-01-01 00:00:00'],
            ['add_time', 'date', 'format'=>'yyyy-MM-dd HH:mm:ss', 'message' => 'add_time非yyyy-MM-dd HH:mm:ss格式'],
        ];
    }


    /*添加*/
    public function addData($data, $app_id)
    {
        // P($data);
        $data['DynamicDataInfo']['app_id'] = $app_id;
        if($this->load($data) and $this->validate()){
            // P($this);
            if($this->save(false)){
                return true;
            }
        }
        return false;
    }


    /*获取内容的*/
    public function getContent()
    {
        $list = $this->hasMany(DynamicDataList::className(), ['info_id' => 'info_id'])
        ->select(['info_id', 'attr_enname', 'attr_value']);
        return $list;
    }

    /*获取中文名称*/
    public function getAttrName()
    {
        $list = $this->hasMany(DynamicDataAttr::className(), ['dynamic_id' => 'dynamic_id'])
        ->select(['dynamic_id', 'attr_name', 'attr_enname', 'attr_type']);
        return $list;
    }

    /*获取标示信息*/
    public function getFlag()
    {
        $flag = $this->hasOne(DynamicDataFlag::className(), ['dynamic_id' => 'dynamic_id']);
        return $flag;
    }

    
}